﻿@page "/SalesChannels/Add"
@page "/SalesChannels/{salesChannelId:int}/Edit"
@using maERP.SharedUI.Models.SalesChannel
@using Microsoft.AspNetCore.Authorization

@attribute [Authorize]

<MudText Typo="Typo.h4" Class="mb-8">Vertriebskanal bearbeiten</MudText>

<MudForm Model="@salesChannel" @ref="@_form">
    <MudGrid>
        <MudItem xs="6">

            <MudSelect T="SalesChannelType" Label="Typ" HelperText="Vertriebskanal-Typ" Placeholder="Typ auswählen" @bind-Value="@salesChannel.Type" Class="mt-6">
                <MudSelectItem Value="SalesChannelType.PointOfSale">Shopware 5</MudSelectItem>
                <MudSelectItem Value="SalesChannelType.Shopware5">Shopware 5</MudSelectItem>
                <MudSelectItem Value="SalesChannelType.Shopware6">Shopware 6</MudSelectItem>
                <MudSelectItem Value="SalesChannelType.WooCommerce">WooCommerce</MudSelectItem>
            </MudSelect>

            <MudTextField @bind-Value="salesChannel.Name"
                          For="@(() => salesChannel.Name)"
                          Label="Name"
                          Required="true"
                          Variant="Variant.Text"
                          InputType="InputType.Text"
                          Class="mt-6" />

            <MudTextField @bind-Value="salesChannel.Url"
                          For="@(() => salesChannel.Url)"
                          Label="API URL"
                          Variant="Variant.Text"
                          InputType="InputType.Url"
                          Class="mt-6" />

            <MudTextField @bind-Value="salesChannel.Username"
                          For="@(() => salesChannel.Username)"
                          Label="API Benutzername"
                          Variant="Variant.Text"
                          InputType="InputType.Text"
                          Class="mt-6" />

            <MudTextField @bind-Value="salesChannel.Password"
                          For="@(() => salesChannel.Password)"
                          Label="API Passwort"
                          Variant="Variant.Text"
                          InputType="InputType.Password"
                          Class="mt-6" />

            <MudSelect T="int" Label="Lager" HelperText="Lager auswählen" Placeholder="Lager auswählen" @bind-Value="@salesChannel.WarehouseId" Class="mt-6">
                @foreach (var warehouse in warehouses)
                {
                    if (salesChannel.WarehouseId == warehouse.Id)
                    {
                        <MudSelectItem Value="@warehouse.Id">@warehouse.Name</MudSelectItem>
                    }
                    else
                    {
                        <MudSelectItem Value="@warehouse.Id">@warehouse.Name</MudSelectItem>
                    }
                }
            </MudSelect>

            <MudText Typo="Typo.h6" Class="mt-6">Produkte</MudText>
            <MudStack Row="true">
                <MudCheckBox @bind-Value="@salesChannel.ImportProducts" Label="Importieren" />
                <MudCheckBox @bind-Value="@salesChannel.ExportProducts" Label="Exportieren" />
            </MudStack>

            <MudText Typo="Typo.h6" Class="mt-6">Kunden</MudText>
            <MudStack Row="true">
                <MudCheckBox @bind-Value="@salesChannel.ImportCustomers" Label="Importieren" />
                <MudCheckBox @bind-Value="@salesChannel.ExportCustomers" Label="Exportieren" />
            </MudStack>

            <MudText Typo="Typo.h6" Class="mt-6">Kunden</MudText>
            <MudStack Row="true">
                <MudCheckBox @bind-Value="@salesChannel.ImportOrders" Label="Importieren" />
                <MudCheckBox @bind-Value="@salesChannel.ExportOrders" Label="Exportieren" />
            </MudStack>

            <MudButton Variant="Variant.Filled"
                       Color="Color.Primary"
                       Size="Size.Large"
                       ButtonType="ButtonType.Button"
                       OnClick="@(Save)"
                       Class="mt-6">Speichern</MudButton>

        </MudItem>
    </MudGrid>
</MudForm>